package com.design.patterns.structuralModel.chainofresponsibility.service.impl;

import com.design.patterns.structuralModel.chainofresponsibility.bean.Request;
import com.design.patterns.structuralModel.chainofresponsibility.service.Middleware;

public abstract class MiddlewareAbstract implements Middleware {
    private Middleware next;

    /**
     * 每一个责任链的一部分都保存着下一个节点的消息，就像单向链表一样
     * @param next
     * @return
     */
    @Override
    public Middleware linkWith(Middleware next) {
        this.next = next;
        return next;
    }

    @Override
    public boolean checkNext(Request request) {
        if (next == null) {
            return true;
        }
        return next.check(request);
    }
}
